<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns:ui="http://java.sun.com/jsf/facelets"
                template="/resources/template/template.xhtml"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns="http://www.w3.org/1999/xhtml"
                xmlns:p="http://primefaces.org/ui">


    <ui:define name="content">

        <h:panelGroup >
            <h:form  >
                <p:growl />
                <p:focus id="selectFocus" context="gpSelect" />
                <p:focus id="detailFocus" context="gpDetail" />



                <p:panel  >
                    <f:facet name="header" >
                        <p:outputLabel value="Manage Departments" ></p:outputLabel>
                        <p:commandButton id="btnBack" value="Back" 
                                         action="/admin_mange_institutions_index" style="float: right;"
                                         ajax="false">
                        </p:commandButton>

                    </f:facet>

                    <h:panelGrid id ="gpVeda" columns="3" styleClass="alignTop" >

                        <h:panelGrid id="gpSelect" columns="1"  >
                            <p:panel >

                                <f:facet name="header" >
                                    <p:outputLabel value="Search Departments" ></p:outputLabel>

                                    <p:commandButton id="btnAdd" value="Add New" action="#{departmentController.prepareAdd()}" style="float: right;"
                                                     update="lstSelect gpDetail detailFocus" process="btnAdd">
                                    </p:commandButton>

                                </f:facet>


                                <h:panelGrid id="gpSelectText" >

                                    <p:inputText value="#{departmentController.selectText}" id="txtSearch" style="standardText" >
                                        <f:ajax event="keyup" execute="@this" render="lstSelect" listener="#{departmentController.fillSearchItems()}" ></f:ajax>

                                    </p:inputText>

                                    <p:selectOneListbox  id="lstSelect"
                                                         value="#{departmentController.current}" 
                                                         styleClass="standardList">
                                        <f:selectItems  value="#{departmentController.searchItems}" var="myItem" itemValue="#{myItem}" itemLabel="#{myItem.name}" ></f:selectItems>
                                        <f:ajax render="gpDetail" execute="lstSelect" ></f:ajax>
                                        <f:ajax event="click" execute="lstSelect" render="gpDetail"  ></f:ajax>
                                    </p:selectOneListbox>

                                </h:panelGrid>
                                <h:panelGrid id="gpSelectButtons" columns="3"  >

                                    <p:commandButton id="btnDelete" 
                                                     onclick="if (!confirm('Are you sure you want to delete this record?'))
                                                                 return false;" 
                                                     action="#{departmentController.delete()}"  
                                                     value="Delete"
                                                     ajax="false">
                                    </p:commandButton>
                                </h:panelGrid>
                            </p:panel>
                        </h:panelGrid  >

                        <p:panel >

                            <f:facet name="header" >

                                <p:outputLabel value="Details of Selected Department" ></p:outputLabel>
                                <p:commandButton id="btnSave" value="Save" action="#{departmentController.saveSelected()}" style="margin-left: 30px;" process="btnSave gpDetail" update="lstSelect gpDetail selectFocus" >
                                </p:commandButton>
                                <p:defaultCommand target="btnSave"/>
                            </f:facet>

                            <p:tabView id="gpDetail" >
                                <p:tab title="Basic Details" >
                                    <h:panelGrid columns="1">
                                        <h:panelGrid id="gpDetailText" columns="2">
                                            <h:outputText id="lblName" value="Name"  ></h:outputText>
                                            <p:inputText autocomplete="off" 
                                                         id="txtName" value="#{departmentController.current.name}" 
                                                         styleClass="longText"></p:inputText>
                                            <h:outputText id="lblTName" value="Name QB"  ></h:outputText>
                                            <p:inputText autocomplete="off" 
                                                         id="txtTName" value="#{departmentController.current.tname}" 
                                                         styleClass="longText"></p:inputText>
                                            <h:outputText value="Code" />                                   
                                            <p:inputText autocomplete="off"  value="#{departmentController.current.departmentCode}"  />

                                            <h:outputText  value="Printing Name" ></h:outputText>
                                            <p:inputText autocomplete="off"  styleClass="longText"
                                                         value="#{departmentController.current.printingName}"  ></p:inputText>
                                            <h:outputText  value="Adress" ></h:outputText>
                                            <p:inputTextarea styleClass="longText" value="#{departmentController.current.address}"  ></p:inputTextarea>
                                            <h:outputText  value="Tel. No. 1" ></h:outputText>
                                            <p:inputText autocomplete="off"  value="#{departmentController.current.telephone1}"  ></p:inputText>
                                            <h:outputText  value="Tel. No. 2" ></h:outputText>
                                            <p:inputText autocomplete="off"  value="#{departmentController.current.telephone2}"  ></p:inputText>
                                            <h:outputText  value="Fax" ></h:outputText>
                                            <p:inputText autocomplete="off"  value="#{departmentController.current.fax}"  ></p:inputText>
                                            <h:outputText  value="Email" ></h:outputText>
                                            <p:inputText autocomplete="off"  value="#{departmentController.current.email}"  ></p:inputText>
                                            <h:outputText id="lblDept" value="Department Type" ></h:outputText>
                                            <h:outputText id="lblDeptTem" value="Department Type" rendered="#{departmentController.current eq null}" ></h:outputText>
                                            <p:selectOneMenu id="cmbDept" value="#{departmentController.current.departmentType}" rendered="#{departmentController.current ne null}" >
                                                <f:selectItem itemLabel="Select the Department Type" />
                                                <f:selectItems value="#{departmentController.departmentType}"/>                                        
                                            </p:selectOneMenu>

                                            <h:outputText id="lblIns" value="Institution" ></h:outputText>
                                            <p:autoComplete  completeMethod="#{institutionController.completeCompany}" 
                                                             var="pta" itemLabel="#{pta.name}" itemValue="#{pta}" forceSelection="true" value="#{departmentController.current.institution}" ></p:autoComplete>


                                        </h:panelGrid>


                                    </h:panelGrid>
                                </p:tab>
                                <p:tab title="Pricing Details">
                                    <h:panelGrid columns="2" >
                                        <h:outputText value="OPD Margin Percenttage " />                                   
                                        <p:inputText autocomplete="off"  value="#{departmentController.current.margin}"  />
                                        <h:outputText value="Pharmacy Margin Percentage " />                                   
                                        <p:inputText autocomplete="off"  value="#{departmentController.current.pharmacyMarginFromPurchaseRate}"  />

                                    </h:panelGrid>
                                </p:tab>
                                <p:tab title="Editing Details" >
                                    <h:panelGrid columns="2" >
                                        <h:outputText id="lblcre" value="Creater" ></h:outputText>
                                        <p:outputLabel value="#{institutionController.current.creater.webUserPerson.name}"/>

                                    </h:panelGrid>
                                </p:tab>
                            </p:tabView>


                        </p:panel>

                    </h:panelGrid>
                </p:panel>
            </h:form>

        </h:panelGroup>

    </ui:define>

</ui:composition>
